package adenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 此处不自定义类型，防止数据库占位符?替换为字符串，在mysql进行匹配时发生类型转换

// 定义常量
const (
	// 首页轮播图
	LOCATION_INDEX_CAROUSEL int = 11

	// 侧边栏
	LOCATION_ASIDE int = 22

	// 文章详情页顶部
	LOCATION_ARTICLE_DETAIL_TOP int = 33
)

// 实现EnumInerface接口
type Location struct {
	enum.Enum[int]
}

func (e *Location) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		LOCATION_INDEX_CAROUSEL: {
			"desc":  "首页轮播",
			"sort":  1,
			"color": "#16baaa",
		},
		LOCATION_ASIDE: {
			"desc":  "侧边栏",
			"sort":  2,
			"color": "#ffb800",
		},
		LOCATION_ARTICLE_DETAIL_TOP: {
			"desc":  "文章详情页顶部",
			"sort":  3,
			"color": "#ff5722",
		},
	}
}

// instanceCache 存储已经创建的实例
var locationInstanceCache = make(map[int]*Location)

// 创建枚举
// 根据value获取枚举
func LocationByValue(value int) *Location {
	if instance, exists := locationInstanceCache[value]; exists {
		return instance
	}
	e := &Location{}
	enum.SetEnumInstance(&e.Enum, e, value)
	locationInstanceCache[value] = e
	return e
}

var LocationEnum *Location = func() *Location {
	e := &Location{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
